<%--
  Created by IntelliJ IDEA.
  User: Wxin
  Date: 20/4/13
  Time: 17:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery.min.js"></script>
    <script>
        // 页面加载绑定单击事件
        // 此处我们的css资源被DispatcherServlet拦截了
        $(function () {
            $("#btn").click(function () {
                // window.alert("你好!");
                // 发送json数据请求
                var user = {'username':'hehe','password':'123','age':30};
                $.ajax({
                    // 编写json格式,设置属性和值
                    url:"user/testAjax",
                    contextType:"application/json",
                    // data:JSON.stringify(user),
                    data:"{'username':'hehe','password':'123','age':30}",
                    dataType:"json",
                    type:"POST",
                    success:function (data) {
                        // data服务器端响应的json的数据，进行解析
                        alert(data);
                        alert(data.username);
                        alert(data.password);
                        alert(data.age);
                    },
                    error:function () {
                        alert("出错啦...")
                    }
                });

                // $.post("user/testAjax", {'username':'hehe','password':'123','age':30});

            });
        });

/*        window.onload=function (ev) {
            var btn = document.getElementById("btn");
            btn.onclick=function (ev1) {
                window.alert("你好!")
            };
        };*/
    </script>
</head>
<body>
    <a href="user/testString">testString</a>
    <br/>

    <a href="user/testVoid">testVoid</a>
    <br/>

    <a href="user/testModelAndView">testModelAndView</a>
    <br/>

    <a href="user/testForwardOrRedirect">testForwardOrRedirect</a>
    <br/>

    <button id="btn">发送ajax的请求</button>
    <br/>

</body>
</html>
